'A new point is added and a few lines updated from DrawTriangle to allow drawing trapezoid.
Private Sub DrawTrap(ByVal x0 As Long, ByVal y0 As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal x3 As Long, ByVal y3 As Long)
Dim y_start As Single, y_end As Single
Dim y_top_change As Single, y_bottom_change As Single
'Only a few added lines to allow for texture mapping.
Private Sub DrawTrapTex(ByVal x0 As Long, ByVal y0 As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal x3 As Long, ByVal y3 As Long)
Dim y_start As Single, y_end As Single
Dim y_top_change As Single, y_bottom_change As Single
Dim x As Long, y As Long
Dim u As Single, v As Single 'new from DrawTrap
Dim du As Single, dv As Single 'new from DrawTrap
y_start = y0
y_end = y3
If x1 = x0 Then Exit Sub
y_top_change = (y1 - y0) / (x1 - x0)
y_bottom_change = (y2 - y3) / (x1 - x0)
du = (Texture1.width - 1) / (x1 - x0) 'new from DrawTrap
For x = x0 To x1
dv = (Texture1.height - 1) / (y_end - y_start) 'new from DrawTrap
v = 0 'new from DrawTrap
For y = y_start To y_end
If (x >= 0) And (x < BackBuffer.width) And (y >= 0) And (y < BackBuffer.height) Then
On Error Resume Next
bbfbits(x, y) = tex1Bits(u, v) 'updated from DrawTrap
'step through, comment out for speed gain
'If Check1.Value = vbChecked Then
' DoEvents
' BackBuffer.FlipBuffer scene.hDC
'End If
End If
v = v + dv 'new from DrawTrap
Next
y_start = y_start + y_top_change
y_end = y_end + y_bottom_change
u = u + du 'new from DrawTrap
Next
End Sub
Private Sub Command4_Click()
If doRotation Then
doRotation = False
Else
Command4.Caption = "Stop 3D Rotation"
doRotation = True
Dim x1 As Single, y As Single, z1 As Single
Dim x2 As Single, z2 As Single, zTrans As Single
Dim angle As Single
Dim halfWidth As Single, halfHeight As Single
Dim x2d1 As Long, y2d1 As Long, x2d2 As Long, y2d2 As Long
Dim xCenter As Long, yCenter As Long
Dim convScl As Long
'surface dimensions
halfWidth = Texture1.width
halfHeight = Texture1.height
y = halfHeight
zTrans = 1500
xCenter = BackBuffer.width / 2
yCenter = BackBuffer.height / 2
convScl = BackBuffer.width
Do While doRotation
DoEvents
BackBuffer.Clear
'calculate the rotation
x1 = Cos(angle * RADIANS) * halfWidth
z1 = Sin(angle * RADIANS) * halfWidth
'since our rotation is done in the center
'just invert the first vertex for the adjacent vertex
x2 = -x1
z2 = -z1
'z translation
z1 = z1 + zTrans
z2 = z2 + zTrans
'x translation
x1 = x1 + 0
x2 = x2 + 0
'convert to 2D coordinates
'we'll just keep our rotation centered along the Y-axis so we'll
'use only two verteces then flip them later for the top two vertices